<?php
$pathArr = explode("/", $_SERVER["PHP_SELF"]);
$contextPath = $pathArr[1];
$rootPath = $_SERVER["DOCUMENT_ROOT"];
include_once $rootPath . "/" . $contextPath . "/apps/ManagerIUDS.php";
$managerIUDS = new ManagerIUDS();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>.: Predicate Detail :.</title>
<?php
require_once($rootPath . "/" . $contextPath . "/includes/css_inc.php");
require_once($rootPath . "/" . $contextPath . "/includes/js_inc.php");
?>
<script type="text/javascript">
			$(document).ready(function(){ 
				$("#save").click(function(){
					var result = true;
					if($("#user_name").val()=="" || $("#user_name").val()==null){
						alert("กรุณากรอกชื่อบัญชีผู้ใช้");
						$("#user_name").focus(); 
						result = false
					}else if($("#password").val()=="" || $("#password").val()==null){
						alert("กรุณากรอกรหัสผ่าน");
						$("#password").focus(); 
						result = false
					}else if($("#confirm_password").val()=="" || $("#confirm_password").val()==null){
						alert("กรุณากรอกยืนยันรหัสผ่าน");
						$("#confirm_password").focus(); 
						result = false
					}else if($("#name").val()=="" || $("#name").val()==null){
						alert("กรุณากรอกชื่อ");
						$("#name").focus(); 
						result = false
					}else if($("#sur_name").val()=="" || $("#sur_name").val()==null){
						alert("กรุณากรอกนามสกุล");
						$("#sur_name").focus(); 
						result = false
					}else if($("#e_mail").val()=="" || $("#e_mail").val()==null){
						alert("กรุณากรอก E-mail");
						$("#price").focus(); 
						result = false
					}else if($("#confirm_password").val() != $("#password").val()){
						alert("กรุณากรอกรหัสผ่านผ่านไม่ตรงกัน");
						$("#password").focus(); 
						result = false
					}
					if(result){
						$("#frm").submit();
					}
				});
				$("#user_name").blur(function(){
					//alert("Hey");
					document.getElementById("img_process").style.display = "inline";
					document.getElementById("img_process").src = "../images/process.gif";
					$.ajax({
						type: "GET",
						url: "../actions/user_action.php",
						data: {mode : "listUserName",userName : $("#user_name").val()},
						contentType: "application/json; charset=utf-8", 
						dataType: "json",
						success: function( data ) {
							if(data.result == "Y"){
								document.getElementById("img_process").src = "../images/cross_bright.png";
								document.getElementById("textError").style.display = "inline";
								$("#user_name").val("");
							}else if(data.result == "N" && ($("#user_name").val() != "" && $("#user_name").val() !=null)){
								document.getElementById("textSuccess").style.display = "inline";
								document.getElementById("img_process").src = "../images/check-icon.png";
							}else{
								document.getElementById("img_process").style.display = "none";
								document.getElementById("textSuccess").style.display = "none";
								document.getElementById("textError").style.display = "none";
								document.getElementById("img_process").src = "";
							}
						},
						error:function (xhr, ajaxOptions, thrownError){
							 alert(thrownError);
					    } 
					});
				});
			}); 
		</script>
</head>
<body>
<center>
			<form name="frm" id="frm" action="../actions/user_action.php" method="POST">
			<table class="" border="0" width="65%">
				<thead class="ui-widget">
					<tr class="ui-widget-header">
						<th colspan="2" align="left">&nbsp;&nbsp;&nbsp;รายละเอียดข้อมูลลงทะเบียน</th>
					</tr>
				</thead>
				<tbody class="ui-widget-content" >
					<tr>
						<td align="right" rowspan="3">ชื่อบัญชีผู้ใช้ : </td>
						<td><input type="text" name="user_name" id="user_name" value=""><span style="color:#ff0000">*</span><img src="" id="img_process"  height="12" width="12" style="display:none;">
						</td>
						<tr>
							<td style="display:none;" id="textError">
								<p style="color:#ff0000">*ชื่อบัญชีผู้ใช้นี้มีคนใช้แล้วกรุณากรอกข้อมูลใหม่</p>
							</td>
						</tr>
						<tr>
							<td style="display:none;" id="textSuccess">
								<p style="color:#ff0000">*ชื่อบัญชีผู้ใช้นี้สามารถใช้งานได้</p>
							</td>
						</tr>
					</tr>
					<tr>
						<td align="right">รหัสผ่าน : </td>
						<td><input type="password" name="password" id="password" value=""><span style="color:#ff0000">*</span> </td>
					</tr>
					<tr>
						<td align="right">ยืนยันรหัสผ่าน : </td>
						<td><input type="password" name="confirm_password" id="confirm_password" value=""><span style="color:#ff0000">*</span> </td>
					</tr>
					<tr>
						<td align="right">ชื่อ : </td>
						<td><input type="text" name="name" id="name" value=""><span style="color:#ff0000">*</span> </td>
					</tr>
					<tr>
						<td align="right">นามสกุล : </td>
						<td><input type="text" name="sur_name" id="sur_name" value=""><span style="color:#ff0000">*</span> </td>
					</tr>
					<tr>
						<td align="right">อีเมล : </td>
						<td><input type="text" name="e_mail" id="e_mail" value=""><span style="color:#ff0000">*</span> </td>
					</tr>
					<tr>
						<td colspan="2"align="center">
							<input type="button" name="save" id="save" value="บันทึก">
							<input type="button" value="ยกเลิก"	onclick="top.location='../index.php';"></td>
						</td>
					</tr>
				</tbody>
			</table>
			<input type="hidden" name="mode" id="mode" value="insert">
			</form>
		</center>
	</body>
</html>